package com.gdth.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.gdth.database.bean.DaoMaster;
import com.gdth.database.bean.DzCpkhXxDjEtcDao;
import com.gdth.database.bean.DzCpkhXxDjPosDao;
import com.gdth.database.bean.NoteDao;
import com.gdth.database.bean.NotificationTDao;
import com.gdth.database.bean.TAppBfrjBfjlDao;
import com.gdth.database.bean.TAppBfrjCpxqDao;
import com.gdth.database.bean.TAppBfrjJbxxbDao;
import com.gdth.database.bean.TAppBfrjJtcybDao;
import com.gdth.database.bean.TAppBfrjLxfsDao;
import com.gdth.database.bean.TAppBfrjThjlDao;
import com.gdth.database.bean.TAppBfrjZcxxbDao;
import com.gdth.database.bean.TAppCanshuDao;
import com.gdth.database.bean.TAppFjxxbDao;
import com.gdth.database.bean.TAppGncdDao;
import com.gdth.database.bean.TAppMediaDao;
import com.gdth.database.bean.TAppSyJyBDao;
import com.gdth.database.bean.TAppTbjlbDao;
import com.gdth.database.bean.TAppTokenDao;
import com.gdth.database.bean.TAppYhDao;
import com.gdth.database.bean.TXtBmDao;
import com.github.yuweiguocn.library.greendao.MigrationHelper;

import org.greenrobot.greendao.database.Database;

/**
 * @author xjc
 * 创建时间： 2020/5/9 11:07 AM
 * @version V1.0
 * 用途:
 */
public class MySQLiteOpenHelper extends DaoMaster.OpenHelper{


    public MySQLiteOpenHelper(Context context, String name) {
        super(context, name);
    }

    public MySQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        if(oldVersion==1){
            deleSQL();
        }
        MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {
            @Override
            public void onCreateAllTables(Database db, boolean ifNotExists) {
                DaoMaster.createAllTables(db, ifNotExists);
            }
            @Override
            public void onDropAllTables(Database db, boolean ifExists) {
                DaoMaster.dropAllTables(db, ifExists);
            }
        }, DzCpkhXxDjEtcDao.class, DzCpkhXxDjPosDao.class, NoteDao.class, NotificationTDao.class,
                TAppBfrjBfjlDao.class, TAppBfrjCpxqDao.class, TAppBfrjJbxxbDao.class, TAppBfrjJtcybDao.class, TAppBfrjLxfsDao.class,
                TAppBfrjThjlDao.class, TAppBfrjZcxxbDao.class, TAppCanshuDao.class, TAppFjxxbDao.class, TAppGncdDao.class,
                TAppMediaDao.class, TAppSyJyBDao.class, TAppTbjlbDao.class, TAppTokenDao.class, TAppYhDao.class, TXtBmDao.class

        );
    }
    public void deleSQL(){
        SQLiteDatabase db=getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        DaoMaster.dropAllTables(daoMaster.getDatabase(),true);
        DaoMaster.createAllTables(daoMaster.getDatabase(),true);
    }
}